<?php

function display($zarray,$field,$delim,$caller,$point){

if (!isset($siteTitle)) { require('../../config.php');}

unset($tmparray);
$tmparray=explode('/',$caller);
$caller=$tmparray[count($tmparray)-1];
$thisPage=$_SESSION['thispage'];
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Order contence</title>
<meta name="robots" content="noindex,nofollow" />
<?php require_once('theme/admintheme.php');?>
</head>
<body>
<div id="wrap">
<?php

	include_once('navigation.php');

	echo "<br />";
//if (isset($_SESSION['zarray'])){echo "Is set ";}
	unset($sarray);
	$cnt=0;
//print_r($zarray);	

	foreach($zarray as $line){
		$tmpline=explode($delim,$line);
		$tmp=str_replace('$',' ',$tmpline[$field]);
		echo "<b>" .$tmp ."</b><br />";
		$sarray[$cnt]=$tmp;
		//echo strlen($tmp) ."  ";
		$cnt++;
	}
	
	?>

<br />
<form action="<?php echo $caller; ?>" method="post" >
<select name="doorder" >
	<?php 
	if ($point<0){ echo '<option selected="">Select</option>';}

	$cnt=0;
	foreach($sarray as $val){
		if ($point==$cnt){ 
			echo '<option selected="' .$cnt .'" value="' .$cnt .'" size="22" >' .$val .'</option>';
		}else{
			echo '<option value="' .$cnt .'" size="22" >' .$val .'</option>';
		}
		$cnt++;
	}
//<br /><br />
	
	?>
</select>
	
<input type="submit" value="Move Up" title="submit" name="up" />
<input type="submit" value="Move Down" title="submit" name="down" />
<input type="submit" value="Save the order" title="submit" name="save" />
</form>

	<?php
	$_SESSION['point']=$point;	
}

function moveup($zarray,$id,$field,$delim,$caller){
	$point=$id;
	if ($id > 0 && $id < count($zarray)){
		$tmp=$zarray[$id];
		$point=$id-1;
		$zarray[$id]=$zarray[$point];
		$zarray[$point]=$tmp;
	}	
	display($zarray,$field,$delim,$caller,$point);
	return $zarray;
}

function movedown($zarray,$id,$field,$delim,$caller){

	$point=$id;
	if ($id > -1 && $id < count($zarray)-1){
		$tmp=$zarray[$id];
		$point=$id+1;
		$zarray[$id]=$zarray[$point];
		$zarray[$point]=$tmp;
	}	
	display($zarray,$field,$delim,$caller,$point);
	return $zarray;
}

?>
